<template>
  <div>
    <i-vxe-table ref="iVxeTableRef" :tableData="tableData" >
      <template #status_template="{ obj }">
        <a-badge status="processing" :color="obj.status==='0'?'':'red'" />
        <span>{{obj.status==='0'?'启用':'禁用'}}</span>
      </template>
      <template #verify_template="{ obj }">
        <span>{{obj.verify==='0'?'验证':'不验证'}}</span>
      </template>
    </i-vxe-table>
     <lib-doc :libDocData="libDocData"></lib-doc>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { IVxeTable } from 'wd-platform-library'
import {
    TableDataInterFace,
    PageInfoInterFace,
    ResultInterFace
} from 'wd-platform-library/lib/src/IVxeTable/src/IVxeTableInterFace'
import LibDoc from '@/components/LibDoc.vue'
import { LibDocInterface } from '@/service/LibDocService'
interface AppResult {
  appName: string;
  status: string;
  verify: string;
}

export default defineComponent({
    name: 'i_from_demo',
    setup () {
        const iVxeTableRef = ref()
        const dataList = [
            {
                appName: '系统管理',
                verify: '1',
                status: '0'
            },
            {
                appName: '产品管理',
                verify: '0',
                status: '0'
            },
            {
                appName: '营销获客',
                verify: '0',
                status: '1'
            },
            {
                appName: '线上资源',
                verify: '0',
                status: '0'
            },
            {
                appName: '订单管理',
                verify: '0',
                status: '0'
            },
            {
                appName: '数据统计',
                verify: '0',
                status: '0'
            }
        ]
        const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        minWidth: 150,
                        title: '应用名称',
                        fixed: 'left'
                    },
                    {
                        field: 'status',
                        minWidth: 80,
                        title: '状态',
                        slots: {
                            default: 'status_template'
                        }
                    },
                    {
                        field: 'verify',
                        minWidth: 80,
                        title: '是否验证',
                        slots: {
                            default: 'verify_template'
                        }
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            }
        })
        const libDocData: LibDocInterface = {
            title: '自定义表格组件',
            docList: [
                {
                    label: '引入组件',
                    value: "import { IVxeTable } from 'wd-platform-library'"
                },
                {
                    label: '创建表格对象',
                    type: 'pre',
                    value: `
     const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        minWidth: 150,
                        title: '应用名称',
                        fixed: 'left'
                    },
                    {
                        field: 'status',
                        minWidth: 80,
                        title: '状态',
                        slots: {
                            default: 'status_template'
                        }
                    },
                    {
                        field: 'verify',
                        minWidth: 80,
                        title: '是否验证',
                        slots: {
                            default: 'verify_template'
                        }
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            }
        })`
                },
                {
                    label: '关键代码',
                    type: 'pre',
                    value: `
    tableInfo: {
                columns: [
                    {
                        field: 'status',
                        minWidth: 80,
                        title: '状态',
                        slots: {
                            default: 'status_template' //自定义展示slot
                        }
                    },
                    {
                        field: 'verify',
                        minWidth: 80,
                        title: '是否验证',
                        slots: {
                            default: 'verify_template' //自定义展示slot
                        }
                    }
                ], // 表头配置
                data: [] // 数据集合
    }
    
    //自定义展示对应html代码
     <i-vxe-table ref="iVxeTableRef" :tableData="tableData" >
      <template #status_template="{ obj }">  //slot名称对应columns  obj:回传的当前行参数
        <a-badge status="processing" :color="obj.status==='0'?'':'red'" />
        <span>{{obj.status==='0'?'启用':'禁用'}}</span>
      </template>
      <template #verify_template="{ obj }">
        <span>{{obj.verify==='0'?'验证':'不验证'}}</span>
      </template>
    </i-vxe-table>
    `
                }
            ]
        }
        return {
            libDocData,
            tableData,
            iVxeTableRef
        }
    },
    components: {
        IVxeTable,
        LibDoc
    }
})
</script>

<style lang="scss" scoped>
.cus_template {
  display: flex;
}
</style>
